package com.sunspring.zdcall.controller.commoncontroller;

import com.sunspring.zdcall.common.SimpleResponse;
import com.sunspring.zdcall.dto.QueueDto;
import com.sunspring.zdcall.dto.SortQueue;
import com.sunspring.zdcall.service.QueueService;
import com.sunspring.zdcall.support.cache.QueueCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * 患者排队信息
 * @Author WuLei
 * @Date 2018/11/28  10:15
 */
@RestController
@RequestMapping("/queue")
public class QueueController {

    @Autowired
    private QueueCache queueCache;

    @Autowired
    private QueueService queueService;

    /**
     * 查看当天的检查室的缓存队列
     * @param deptId 部门ID
     * @param checkRoomId 检查室ID
     */
    @GetMapping("/cacheCheckRoom")
    public SimpleResponse cacheInfo(String deptId,String checkRoomId) {
        LinkedList<QueueDto> deptQueue = queueCache.get(deptId,checkRoomId);
        return SimpleResponse.success(deptQueue);
    }

    /**
     * 查看当天的科室的缓存队列
     * @param deptId 科室ID
     */
    @GetMapping("/cacheDept")
    public SimpleResponse cacheInfo(String deptId) {
        Map<String,LinkedList<QueueDto>> map = queueCache.get(deptId);
        List<SortQueue> sortQueues = new ArrayList<>();
        if (!CollectionUtils.isEmpty(map)) {
            map.forEach((s, queueDtos) -> {
                if (!CollectionUtils.isEmpty(queueDtos)) {
                    LinkedList<QueueDto> todayQueue = new LinkedList<>();
                    SortQueue sortQueue = new SortQueue();
                    sortQueue.setCheckId(queueDtos.get(0).getCheckId());
                    sortQueue.setCheckRoom(queueDtos.get(0).getCheckRoom());
                    sortQueue.setQueueDtoList(todayQueue);
                    sortQueues.add(sortQueue);
                }
            });

        }
        return SimpleResponse.success(sortQueues);
    }


    @GetMapping("/info")
    public SimpleResponse info() {
        return SimpleResponse.success();
    }

}
